<template>
  <div class="app-container p-rel">
    <div class="container-title">查询</div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-row :gutter="15">
        <el-col :lg="8" :xl="6">
          <el-form-item label="名称" prop="enterpriseName">
            <el-input
              v-model="queryParams.enterpriseName"
              placeholder="请输入名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="8">
          <el-form-item label="统一信用代码/登记号查询" prop="creditCode" label-width="180px">
            <el-input
              v-model="queryParams.creditCode"
              placeholder="请输入统一信用代码/登记号查询"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="类型" prop="type">
            <el-select v-model="queryParams.typeIdList" multiple placeholder="请选择类型" clearable style="width: 100%;">
              <el-option
                v-for="dict in dict.type.enterprise_info_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="类别" prop="category">
            <el-select v-model="queryParams.category" placeholder="请选择类别" clearable style="width: 100%;">
              <el-option
                v-for="item in categoryList"
                :key="item.id"
                :label="item.categoryName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
           <el-form-item label="镇/街道" prop="town">
            <el-select v-model="queryParams.townCode" placeholder="请选择镇/街道" clearable style="width: 100%;">
              <el-option
                v-for="item in townStreetList"
                :key="item.id"
                :label="item.shortname"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="详细地址" prop="addr">
            <el-input
              v-model="queryParams.addr"
              placeholder="请输入详细地址"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
            <el-button type="primary" icon="" size="" @click="handleQuery">搜索</el-button>
            <el-button icon="" size="" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
       <el-button
          size="mini"
          type="primary"
          @click="handleTest"
        >同步工商数据</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="infoList">
      <el-table-column type="index" width="55" align="center"  label="序号"/>
      <el-table-column label="名称" align="center" prop="enterpriseName" />
      <el-table-column label="统一信用代码/登记号" align="center" prop="creditCode" />
      <el-table-column label="类型" align="center" prop="C" width="180px"/>
      <el-table-column label="类别" align="center" prop="D"/>
      <el-table-column label="类目" align="center" prop="E"/>
      <el-table-column label="所在镇/街道" align="center" prop="town" />
      <el-table-column label="详细地址" align="center" prop="addr" />
      <el-table-column label="联系电话" align="center" prop="contactNumber" />
      <el-table-column label="一般/严重" align="center" prop="hazardLevel">
           <template slot-scope="scope">
                  {{hazardLevelFilter(scope.row.hazardLevel)}}
            </template>
      </el-table-column>
      <el-table-column label="企业类型" align="center" prop="hazardEnterpriseType">
              <template slot-scope="scope">
                  {{hazardEnterpriseFilter(scope.row.hazardEnterpriseType)}}
            </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200px">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              @click="handleInfo(scope.row,'REPORT')"
          >查看预评价报告</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleInfo(scope.row,'EXAMINE')" 
          >审核改扩材料</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getHazardEnterpriseFn"
    />
  </div>
</template>

<script>
import { getCategoryList,getTownStreetList} from "@/api/zhangping/publicPlaceHealth";
import { getHazardEnterprise} from "@/api/zhangping/occupational";
export default {
  name: "Info",
   dicts: ['quantitative_level', 'hazard_level','hazard_enterprise_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      infoList: [],
      // 查询参数
      queryParams: {  
        enterpriseName:'', // 企业名称
        creditCode:'',  // 统一社会信用代码
        typeList:'', //类型
        category:'',   // 类别
        addr:'',  // 详细地址
        townCode:'',  // 街道
        pageNum: 1,
        pageSize: 10,
      },
      categoryList:[],
      townStreetList:[]
    };
  },
  created() {
    this.loading = false
    this.getHazardEnterpriseFn()
    this.getCategoryListFn()
    this.getTownStreetListFn()
  },
  methods: {
     // 获取列表 
    getHazardEnterpriseFn(){
        getHazardEnterprise(this.queryParams).then(res=>{
                if(res.code == 200){
                     this.infoList = res.rows
                     this.total = res.total
                }else{
                     this.$message.error(res.msg);  
                }    
         })
    },
     getCategoryListFn(){
          let data ={
                type:'zyws'
          }
          getCategoryList(data).then(res=>{
              if(res.code == 200){
                    this.categoryList = res.data
              }else{
                    this.$message.error(res.msg);  
              } 
          })  
    }, 
     getTownStreetListFn(){
           getTownStreetList().then(res=>{
              if(res.code == 200){
                    this.townStreetList = res.data
              }else{
                    this.$message.error(res.msg);  
              } 
          })  
    }, 
    hazardLevelFilter(type){
          let hazardLevel = this.dict.type.hazard_level
          let name = ''
          hazardLevel.forEach((item)=>{
                 if(item.value == type){
                        name = item.label
                 }            
           })
           return name
    },
    hazardEnterpriseFilter(type){
          let hazardEnterprise= this.dict.type.hazard_enterprise_type
          let name = ''
          hazardEnterprise.forEach((item)=>{
                 if(item.value == type){
                        name = item.label
                 }            
           })
           return name
    },
    // 表单重置
    reset() {
      this.form = {
          enterpriseName:'', // 企业名称
          creditCode:'',  // 统一社会信用代码
          category:'',   // 类别
          addr:'',  // 详细地址
          elvel:'', // 量子化分级评定等级
          town:'',  // 街道
          pageNum: 1,
          pageSize: 10,
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getHazardEnterpriseFn()
    },
    handleTest(){

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.handleQuery();
    },
    handleInfo(row,type) {
          if(type === 'EXAMINE'){
               this.$router.push(`/careerHygiene/test5/materials?id=${row.id}&authStatus=${row.authStatus}`)
          }else{

          }         
    },
  }
};
</script>
